{include file='public/head' /}
<style type="text/css">
  .tablelist tr {
    border:1px solid #CFCFCF;
  }
  .tablelist tr td,.tablelist tr th{
    border:1px solid #CFCFCF;
  }
</style>
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main" style="padding:10px">
        <h1 class="page-header">订单列表 <!-- <button type="button" class="btn btn-danger"  title="删除全部选中" id="deleteSelect">删除</button> -->
        </h1>
        <div class="table-responsive" style="margin-top: -30px;border:none;">
          <form action="{:url('admin/order/index')}" method="get" class="navbar-form navbar-right" role="search" style="margin-top: 20px;">
           <div class="input-group">
              <input type="text" class="form-control" autocomplete="off" placeholder="键入关键字搜索" value='{$Think.get.key}' name="key" style="width:190px">
            <span class="input-group">
             <input class="btn btn-primary" type="submit" value="搜索" style="border-radius: 0 3px 3px 0">&nbsp;
             <button class="btn btn-primary" name="all" value="1">显示全部</button>
              </span> 
            </div>  
           </form>
          <table class="table table-striped table-hover tablelist" >
            <thead>
              <tr style="background-color: #3399CC;color: white">
                <th><input type="checkbox" id="all" style="position: relative;top:2px"/><span class="glyphicon glyphicon-th-large"></span> <span >选择</span></th>
                <th><span class="glyphicon glyphicon-user"></span> <span>用户名</span></th>
                <th><span class="glyphicon glyphicon-map-marker"></span> <span>订单号</span></th>
                <th><span class="glyphicon glyphicon-map-marker"></span> <span>期数</span></th>
                <th><span class="glyphicon glyphicon-tags"></span> <span>下单金额</span></th>
                <th><span class="glyphicon glyphicon-flag"></span> <span>涨跌</span></th>
                <th><span class="glyphicon glyphicon-repeat"></span> <span>状态</span></th>
                <th><span class="glyphicon glyphicon-education"></span> <span>收益</span></th>
                <th><span class="glyphicon glyphicon-time"></span> <span>下注时间</span></th>
               <!--  <th><span class="glyphicon glyphicon-pencil"></span> <span>操作</span></th> -->
              </tr>
            </thead>
            <tbody id='bodyss'>
            </tbody>
          </table>
        </div>
        <footer class="message_footer" style="margin-top: -10px;">
        {if condition="$all eq 1"}
        {else/}
        <span style="float: left;margin-top: 15px;">第{$data->currentPage()} 页 / 共 {$data->lastPage()} 页 ( 总 共 {$data->total()} 条 记 录 )</span> 
        <div style="float: right;margin-top: -10px;">  
        <div class="page" style="margin-top: 5px;">
        {$data->render()}
        </div>
        </div>
        {/if}
        </footer>
    </div>
  </div>
</section>
<script>
  //单条记录删除
  $('.del').click(function(){
      var del = confirm("你确定要删除吗？");
       if(del == false){
        return false;
      }  
  });
  //多选删除
  $('#deleteSelect').click(function(){
    //获取【被选择】的行的id
      var trObj = $(".tablelist tbody tr");
      var ids = new Array();
      var mainObjs = new Array();
      //遍历每一行
      for($i=0;$i<trObj.length;$i++){
         if(trObj.eq($i).find("input").attr('checked')){
            //组装ids数组
            ids[ids.length]=trObj.eq($i).find("input").val();
            //组装mainObj数组
            mainObjs[mainObjs.length]=trObj.eq($i);
         }
      }   
    if(ids.length>0){
        //启动ajax
        $.ajax({
            url:"{:url('deleteall')}",
            type:'post',
            data:{'id':ids},
            async:false, 
            dataType:'json',
            success:function (d) {
                console.log(d);
            if(d==1) {
                var a = confirm("你确定要删除吗？");
                if(a == true){
                   //将前端被选择的多选框所在的行移除DOM
                    for($i=0;$i<mainObjs.length;$i++){
                        mainObjs[$i].fadeOut(500,function(){
                            $(this).remove();
                            history.go(0);
                        });
                    }
                }else{
                   history.go(0);
                }
              } else if (d == 2) {
                     //删除失败
                   alert('删除失败');
               }

            }

        });
    }else{
       alert("你没有选择要删除的内容，请选择后再【批量删除】");
    }  
 
  });
  //全选或全不选
  $("#all").click(function(){ 
      if(this.checked){
         $(".tablelist tbody tr :checkbox").attr("checked", true);
        
      }else{
         $(".tablelist tbody tr :checkbox").removeAttr("checked", false);
      }
  });

  function f(){
     $.ajax({
         type: "post", //请求的方式，也有get请求
         url: "{:url('admin/order/index2')}", //请求地址，后台提供的,这里我在本地自己建立了个json的文件做例子
         // data: {name:name},//data是传给后台的字段，后台需要哪些就传入哪些
         dataType: "json", //json格式，后台返回的数据为json格式的。
         success: function(result){
              // console.log(result.data);
              str = "";
              for (s = 0; s < result.data.length; s++) {
                // $("#bodyss").empty();
                // alert(stu.oid);
                var stu = result.data[s];
                str = "<tr align='center'>";
                str += "<td><input type='checkbox' class='input-control' value='" + stu.oid + "'/>" + stu.oid + "</td> ";
                str += "<td>" + stu.username + "</td>";
                str += "<td>" + stu.codeifd + "</td>";
                str += "<td>" + stu.qishu + "</td>";
                str += "<td>" + stu.money + "</td>";
                if(stu.updown == 1){
                  str += "<td>买涨</td>";
                }else{
                  str += "<td>买跌</td>";
                }
                if(stu.status == 1){
                  str += "<td>已中奖</td>";
                }else if(stu.status == 0){
                  str += "<td>未中奖</td>";
                }else{
                  str += "<td>未开奖</td>";
                }
                str += "<td>" + stu.winmoney + "</td>";
                str += "<td>" + stu.ordertime + "</td>";
              }

              str += "<tr><td colspan='10' style='color: red'><span style='float: right;'>订单总计 :"+{$moneys} +"| 收益总计 : " + {$winmoneys}+"&nbsp;</span></td>";
                str += "<tr>";
                // console.log(str);
              $("#bodyss").html(str);
              
             // var dataObj = result, //返回的result为json格式的数据
             // con = "";
             // $.each(dataObj, function(index, item){
             //     con += "<li>姓名："+item.name+"</li>";
             //     con += "<li>性别："+item.sex+"</li>";
             //     con += "<li>现居地："+item.address+"</li>";
             //     con += "<li>岗位："+item.job+"</li>";
             // });

             // console.log(con);    //可以在控制台打印一下看看，这是拼起来的标签和数据
             // $("#con").html(con); //把内容入到这个div中即完成
         } 
     })
  }

  window.setInterval(f, 20000);
</script>
</body>
</html>
